<template>
	<view class="login-container">

		<view class="wechatapp">
			仁济药业
		</view>
		<view class="login-btn">
			<!-- #ifdef MP-WEIXIN -->
			<button class="btn-normal" @click="getUserInfo">登录</button>
			<!-- #endif -->
			
		</view>
		<view class="no-login-btn">
			<navigator url="/pages/login/regiester" hover-class="navigator-hover">
			    <button class="btn-normal">注册</button>
			</navigator>
		</view>
		<view class="bottom-box">
			<view class="left"><image src="../../static/admin.svg"></image></view>
			<view class="right"><image src="../../static/salesman.svg"></image></view>
		</view>
	</view>
</template>
<script>
	export default {
		data() {
			return {
				background: '',
				listData: [],
				invitation_id: 0
			}
		},
		onLoad(e) {
			this.invitation_id = uni.getStorageSync('invitation_id') ? uni.getStorageSync('invitation_id') : 0;
		},
		methods: {
			getUserInfo: function() {
				let self = this;
				wx.getUserProfile({
					lang: 'zh_CN',
					desc: '用于完善会员资料', 
					success: (res) => {
						if (res.errMsg !== 'getUserProfile:ok') {
							return false;
						}
						uni.showLoading({
							title: "正在登录",
							mask: true
						});
						// 执行微信登录
						wx.login({
							success(res_login) {
								// 发送用户信息
								self._post('user.user/login', {
									invitation_id: self.invitation_id,
									code: res_login.code,
									user_info: res.rawData,
									encrypted_data: encodeURIComponent(res.encryptedData),
									iv: encodeURIComponent(res.iv),
									signature: res.signature,
									referee_id: uni.getStorageSync('referee_id'),
									source: 'wx'
								}, result => {
									// 记录token user_id
									uni.setStorageSync('token', result.data.token);
									uni.setStorageSync('user_id', result.data.user_id);
									// 执行回调函数
									uni.navigateBack();
								}, false, () => {
									uni.hideLoading();
								});
							}
						});
					}
				});
			},
		},
	}
</script>

<style>
	.login-container {
		padding: 30rpx;
	}

	.wechatapp {
		padding: 200rpx 0 80rpx;
		border-bottom: 1rpx solid #e3e3e3;
		margin-bottom: 72rpx;
		text-align: center;
		font-size: 80rpx;
		font-weight: 400;
		color: #04ca0e;
	}


	.login-btn {
		padding: 0 20rpx;
	}

	.login-btn button {
		height: 88rpx;
		line-height: 88rpx;
		background: #04be01;
		color: #fff;
		font-size: 30rpx;
		border-radius: 999rpx;
		text-align: center;
	}

	.no-login-btn {
		margin-top: 20rpx;
		padding: 0 20rpx;
	}

	.no-login-btn button {
		height: 88rpx;
		line-height: 88rpx;
		/* background: #dfdfdf; */
		color: #a9a9a9;
		font-size: 30rpx;
		border-radius: 999rpx;
		text-align: center;
	}
	
	.bottom-box{
		position: absolute;
		bottom: 20rpx;
		width: 100%;
	}
	.bottom-box image{
		float: left;
		width: 80rpx;
		height: 80rpx;
	}
	.left{
		width: 80rpx;
		height: 80rpx;
		float: left;
	}
	.right{
		width: 80rpx;
		height: 80rpx;
		margin-right: 56rpx;
		float: right;
	}
</style>
